package com.it.day6;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * ClassName: AtomicReferenceDemo
 * Description: 原子引用
 *
 * @Author: csx
 * @Create: 2025/5/12 - 16:36
 * @version: v1.0
 */
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User zs = new User("张三", 18);
        User ls = new User("李四", 20);

        AtomicReference<User> reference = new AtomicReference<>();

        reference.set(zs);

        System.out.println(reference.compareAndSet(zs, ls) + "\t" + reference.get());
        System.out.println(reference.compareAndSet(zs, ls) + "\t" + reference.get());
    }
}

@Getter
@ToString
@AllArgsConstructor
class User{
    String name;
    int age;
}















